<?php

namespace app\system\controller;


use app\common\model\MessageModel;


class MessageController extends BaseController
{

  /**
   * 不需要登陆的方法
   * @var array
   */
  protected $noLogin = [];

  /**
   * 不检测权限方法
   * @var array
   */
  protected $noCheck = [];



  /**
   * 当前模型
   * @var null
   */
  protected $model = null;

  /**
   * 初始化
   */
  public function __construct()
  {
    parent::__construct();
    $this->model = new MessageModel();
  }

  /**
   * 首页
   * @return mixed
   * @throws \Exception
   */
  public function index()
  {
    if ($this->request->isAjax()) {
      return $this->getPage();
    }
    return $this->fetch();
  }


  /**
   * 编辑
   * @return string
   * @throws \Exception
   */
  public function edit()
  {
    if ($this->request->isAjax()) {
      $data = $this->request->param();
      $this->validate($data, [
          'reply|回复' => 'require',
      ]);
      $this->model->edit($data);
      $this->success('操作成功');
    }
    $id   = $this->request->param('id/d');
    $info = $this->model->where('id', $id)->find();
    $this->assign('info', $info);
    return $this->fetch();
  }



  /**
   * 删除
   * @return string
   * @throws \Exception
   */
  public function del()
  {
    $id = $this->request->param('id');
    $this->model->del($id);
    $this->success('操作成功');
  }
}
